package com.pipayshop.controller;

import com.pipayshop.entity.ShopCommodityLiveInfo;
import com.pipayshop.entity.dto.ShopCommodityLiveInfoListDTO;
import com.pipayshop.entity.vo.*;
import com.pipayshop.exception.BusinessException;
import com.pipayshop.service.HotelShopCommodityLiveInfoService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import jakarta.annotation.Resource;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.*;
import java.util.List;


@Api(value = "实体店相关接口", tags = "实体店相关接口")
@RestController
@RequestMapping("/pipayshopapi/store-commodity-live-info")
@Slf4j
public class HotelShopHotelController {

    @Resource
    private HotelShopCommodityLiveInfoService shopCommodityLiveInfoService;


    @PostMapping("insertShopLiveInfo")
    @ApiOperation("发布实体店酒店的服务")
    public ResponseVO<String> insertShopLiveInfo(@RequestBody ShopCommodityLiveInfoVO1 shopCommodityLiveInfo) {
        try {
            boolean result = shopCommodityLiveInfoService.insertShopLiveInfo(shopCommodityLiveInfo);
            return result ? ResponseVO.getSuccessResponseVo("publish_hotel_service_success") : ResponseVO.getFalseResponseVo("publish_hotel_service_failed_contact_staff");
        }catch (BusinessException e) {
            throw new BusinessException(e.getMessage());
        }  catch (Exception e) {
            e.printStackTrace();
            log.error(e.getMessage());
            throw new BusinessException("publish_hotel_service_failed_contact_staff");
        }
    }

    @PostMapping("updateHotelInfoByRoomId")
    @ApiOperation("通过房间Id修改房型信息")
    public ResponseVO<String> updateHotelInfoByRoomId(@RequestBody ShopCommodityLiveInfoVO4 shopCommodityLiveInfoVO4) {
        try {
            boolean result = shopCommodityLiveInfoService.updateHotelInfoByRoomId(shopCommodityLiveInfoVO4);
            return result ? ResponseVO.getSuccessResponseVo("update_hotel_service_success") : ResponseVO.getFalseResponseVo("update_hotel_service_failed_contact_staff");
        }catch (BusinessException e) {
            throw new BusinessException(e.getMessage());
        }  catch (Exception e) {
            e.printStackTrace();
            log.error(e.getMessage());
            throw new BusinessException("update_hotel_service_failed_contact_staff");
        }
    }

    @PostMapping("insertShopLive")
    @ApiOperation("发布实体店酒店的服务")
    public ResponseVO<String> insertShopLive(@RequestBody ShopCommodityLiveInfo shopCommodityLiveInfo) {
        try {
            boolean result = shopCommodityLiveInfoService.insertShopLive(shopCommodityLiveInfo);
            return result ? ResponseVO.getSuccessResponseVo("publish_hotel_service_success") : ResponseVO.getFalseResponseVo("publish_hotel_service_failed_contact_staff");
        } catch (Exception e) {
            e.printStackTrace();
            log.error(e.getMessage());
            throw new BusinessException("publish_hotel_service_failed_contact_staff");
        }
    }

    @PostMapping("selectShopCommodityLiveInfoList")
    @ApiOperation("根据实体店id和入住时间和离店时间来搜索房型")
    public ResponseVO<List<ShopCommodityLiveInfoListVO>> selectShopCommodityLiveInfoList(@RequestBody ShopCommodityLiveInfoListDTO shopCommodityLiveInfoListDTO) {
        try {
            List<ShopCommodityLiveInfoListVO> result = shopCommodityLiveInfoService.selectShopCommodityLiveInfoList(
                    shopCommodityLiveInfoListDTO.getShopId(),
                    shopCommodityLiveInfoListDTO.getStartTime(),
                    shopCommodityLiveInfoListDTO.getEndTime()
            );
            return ResponseVO.getSuccessResponseVo(result);
        } catch (Exception e) {
            e.printStackTrace();
            log.error(e.getMessage());
            throw new BusinessException("query_room_types_by_time_failed_contact_staff");
        }
    }

    @PostMapping("selectShopEvaluateCount/{shopId}")
    @ApiOperation("获取实体店酒店评价数")
    public ResponseVO<Integer> selectShopEvaluateCount(@PathVariable String shopId) {
        try {
            Integer result = shopCommodityLiveInfoService.selectShopEvaluateCount(shopId);
            return ResponseVO.getSuccessResponseVo(result);
        } catch (Exception e) {
            e.printStackTrace();
            log.error(e.getMessage());
            throw new BusinessException("retrieve_hotel_reviews_count_failed_contact_staff");
        }
    }

    @GetMapping("selectShopCommodityLiveVO/{pages}/{limit}")
    @ApiOperation("查找实体店酒店的服务列表")
    public ResponseVO<PageDataVO> selectShopCommodityLiveInfoVO(@PathVariable Integer pages, @PathVariable Integer limit) {
        try {
            PageDataVO result = shopCommodityLiveInfoService.selectShopCommodityLiveInfoVO(limit, pages);
            return ResponseVO.getSuccessResponseVo(result);
        } catch (Exception e) {
            e.printStackTrace();
            log.error(e.getMessage());
            throw new BusinessException("query_hotel_services_list_failed_contact_staff");
        }
    }

}
